Skip to content

fix: teardown UI sibling gracefully on ok start exit#702

Closed
Adityakk9031 wants to merge 1 commit into
inkeep:mainfrom
Adityakk9031:fix-stale-ui-process
Closed

fix: teardown UI sibling gracefully on ok start exit#702
Adityakk9031 wants to merge 1 commit into
inkeep:mainfrom
Adityakk9031:fix-stale-ui-process

Conversation

@Adityakk9031

Copy link
Copy Markdown
Contributor

Resolves #692

Description

This PR fixes an issue where stopping the server (ok start) via Ctrl+C would leave a detached, stale ok ui process running in the background, which locked up the port.

Previously, when a user interrupted the ok start command, the CLI correctly tore down the backend services but did not signal the sibling ok ui process (which runs detached). The UI process would persist in the background until its 12-hour safety timer expired.

What Changed

  • Extracted Teardown Logic: The UI teardown procedure—previously isolated inside the server's idle timeout handler (buildIdleShutdownHandler)—was extracted into a reusable teardownUiSibling helper.
  • Wired into System Shutdown: Hooked teardownUiSibling into the standard SIGINT and SIGTERM shutdown handlers within runStartCommand.
  • Now, when you shut down the primary server, the parent explicitly reads the lockfile, sends a SIGTERM to the sibling UI process, waits gracefully for it to exit, and escalates to SIGKILL if it gets stuck.

Testing

  • Confirmed that pressing Ctrl+C during ok start --open now correctly kills both the collab server and the proxying UI process.
  • Changeset included for automated release notes.

@CLAassistant

CLAassistant commented Jul 20, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Adityakk9031

Copy link
Copy Markdown
Contributor Author

@tim-inkeep have a look

@github-actions

Copy link
Copy Markdown

I could not sync this PR automatically. A maintainer will look into it.

The diff could not be applied on our side. This is a bridge-side issue, not a problem with your PR (which is already based on the latest public base); a maintainer will look into it.

Falling back to direct application...
error: cannot apply binary patch to 'public/open-knowledge/.changeset/stale-ui-shutdown.md' without full index line
error: public/open-knowledge/.changeset/stale-ui-shutdown.md: patch does not apply
Applied patch to 'public/open-knowledge/packages/cli/src/commands/start.ts' cleanly.

@tim-inkeep
tim-inkeep requested a review from mike-inkeep July 21, 2026 18:28
inkeep-oss-sync Bot pushed a commit that referenced this pull request Jul 22, 2026
…its via a signal (#2795)

Fixes #692: `ok start` spawns a detached `ok ui` process
for the editor shell. On Ctrl+C (SIGINT/SIGTERM) the CLI destroyed the collab
server but never signalled the UI child, which lingered until its 12h safety
timer — holding its port so the next `ok start` bound a different one.

The signal path now runs the same guarded UI teardown as idle-shutdown, before
destroy releases server.lock. The SIGTERM → grace-poll → SIGKILL escalation is
factored out of `buildIdleShutdownHandler` into a shared `teardownUiSibling`, so
both call sites honor the SAME ownership guard: `spawnedUiPid` scopes the kill to
the sibling this process spawned, leaving a lock holder we did not spawn (a
desktop shell, another session) untouched. `BootedStartServer` now exposes
`spawnedUiPid` so the signal handler passes the owned pid through; the signal
path's teardown is wrapped so a failure there never bypasses destroy().

Reworks community PR #702 by @Adityakk9031, preserving the
`spawnedUiPid` ownership guard that #702 dropped and fixing its changeset
(correct package name, no BOM). Adds `teardownUiSibling` unit tests covering the
signal path's guard.

Co-authored-by: Aditya kumar singh <143548997+Adityakk9031@users.noreply.github.com>
GitOrigin-RevId: 67089dae1d813dbd3470369c7fd73142801a67c7
inkeep-oss-sync Bot pushed a commit that referenced this pull request Jul 22, 2026
…its via a signal (#2795)

Fixes #692: `ok start` spawns a detached `ok ui` process
for the editor shell. On Ctrl+C (SIGINT/SIGTERM) the CLI destroyed the collab
server but never signalled the UI child, which lingered until its 12h safety
timer — holding its port so the next `ok start` bound a different one.

The signal path now runs the same guarded UI teardown as idle-shutdown, before
destroy releases server.lock. The SIGTERM → grace-poll → SIGKILL escalation is
factored out of `buildIdleShutdownHandler` into a shared `teardownUiSibling`, so
both call sites honor the SAME ownership guard: `spawnedUiPid` scopes the kill to
the sibling this process spawned, leaving a lock holder we did not spawn (a
desktop shell, another session) untouched. `BootedStartServer` now exposes
`spawnedUiPid` so the signal handler passes the owned pid through; the signal
path's teardown is wrapped so a failure there never bypasses destroy().

Reworks community PR #702 by @Adityakk9031, preserving the
`spawnedUiPid` ownership guard that #702 dropped and fixing its changeset
(correct package name, no BOM). Adds `teardownUiSibling` unit tests covering the
signal path's guard.

Co-authored-by: Aditya kumar singh <143548997+Adityakk9031@users.noreply.github.com>
GitOrigin-RevId: 67089dae1d813dbd3470369c7fd73142801a67c7
inkeep-oss-sync Bot pushed a commit that referenced this pull request Jul 22, 2026
…its via a signal (#2795)

Fixes #692: `ok start` spawns a detached `ok ui` process
for the editor shell. On Ctrl+C (SIGINT/SIGTERM) the CLI destroyed the collab
server but never signalled the UI child, which lingered until its 12h safety
timer — holding its port so the next `ok start` bound a different one.

The signal path now runs the same guarded UI teardown as idle-shutdown, before
destroy releases server.lock. The SIGTERM → grace-poll → SIGKILL escalation is
factored out of `buildIdleShutdownHandler` into a shared `teardownUiSibling`, so
both call sites honor the SAME ownership guard: `spawnedUiPid` scopes the kill to
the sibling this process spawned, leaving a lock holder we did not spawn (a
desktop shell, another session) untouched. `BootedStartServer` now exposes
`spawnedUiPid` so the signal handler passes the owned pid through; the signal
path's teardown is wrapped so a failure there never bypasses destroy().

Reworks community PR #702 by @Adityakk9031, preserving the
`spawnedUiPid` ownership guard that #702 dropped and fixing its changeset
(correct package name, no BOM). Adds `teardownUiSibling` unit tests covering the
signal path's guard.

Co-authored-by: Aditya kumar singh <143548997+Adityakk9031@users.noreply.github.com>
GitOrigin-RevId: 67089dae1d813dbd3470369c7fd73142801a67c7
@mike-inkeep

mike-inkeep commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Thank you @Adityakk9031 -- merged this with full attribution to your PR and github account in commit 8a7779b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: node process not cleaned up on server close

3 participants